﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using ChanExt;
using C.Unite;
using C.Entities;

namespace ArtLand.OA.Project.Project
{
    public partial class Pro_CustorChange : CommonPageBase
    {
        public string ContentS = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataBaseHelper.BindDrp(Drp_CUTYPE_FI, EnumData.DataBaseEunm.CUTYPE_FI);
                DataBaseHelper.BindDrp(Drp_CUTYPE_SE, EnumData.DataBaseEunm.CUTYPE_SE);
                DataBaseHelper.BindDrp(Drp_CUTYPE_TH, EnumData.DataBaseEunm.CUTYPE_TH);
                btnClose.OnClientClick = ActiveWindow.GetHideReference();
                LoadData();
            }
        }

        protected void LoadData()
        {
            if (!string.IsNullOrEmpty(Request["id"]))
            {
                Proj_Custor Cus = TbsDbSession.Default.From<Proj_Custor>().Where(Proj_Custor._.ID == int.Parse(Request["id"])).ToFirst();
                if (Cus != null)
                {
                    txt_CUTNUB.Text = Cus.CUTNUB;
                    Drp_CUTYPE_FI.SelectedValue = Cus.CUTYPE_FI;
                    Drp_CUTYPE_SE.SelectedValue = Cus.CUTYPE_SE;
                    Drp_CUTYPE_TH.SelectedValue = Cus.CUTYPE_TH;
                    txt_CUTNAM.Text = Cus.CUTNAM;
                    txt_ADDRES.Text = Cus.ADDRES;
                    txt_CONTAT.Text = Cus.CONTAT;
                    txt_TELPHO.Text = Cus.TELPHO;
                    txt_UEMAIL.Text = Cus.UEMAIL;
                    txt_ElseTel.Text = Cus.ElseTel;
                    txt_HomeTel.Text = Cus.HomeTel;
                }
            }
        }


        protected void btnSave_Click(object sender, EventArgs e)
        {
            int returnvalue = 0;
            Proj_Custor Cus = new Proj_Custor();
            if (!string.IsNullOrEmpty(Request["id"]))
            {
                Cus.ID = int.Parse(Request["id"]);
                Cus.Attach();
                Cus.CUTNUB = txt_CUTNUB.Text;
                Cus.CUTYPE_FI = Drp_CUTYPE_FI.SelectedValue;
                Cus.CUTYPE_SE = Drp_CUTYPE_SE.SelectedValue;
                Cus.CUTYPE_TH = Drp_CUTYPE_TH.SelectedValue;
                Cus.CUTNAM = txt_CUTNAM.Text;
                Cus.ADDRES = txt_ADDRES.Text;
                Cus.CONTAT = txt_CONTAT.Text;
                Cus.TELPHO = txt_TELPHO.Text;
                Cus.UEMAIL = txt_UEMAIL.Text;
                Cus.ElseTel = txt_ElseTel.Text;
                Cus.HomeTel = txt_HomeTel.Text;
                Cus.PingYing = PinYinConverter.GetFirst(txt_CUTNAM.Text);
                returnvalue = TbsDbSession.Default.Update<Proj_Custor>(Cus);
            }
            else
            {
                Cus.DeAttach();
                Cus.CUTNUB = txt_CUTNUB.Text;
                Cus.CUTYPE_FI = Drp_CUTYPE_FI.SelectedValue;
                Cus.CUTYPE_SE = Drp_CUTYPE_SE.SelectedValue;
                Cus.CUTYPE_TH = Drp_CUTYPE_TH.SelectedValue;
                Cus.CUTNAM = txt_CUTNAM.Text;
                Cus.ADDRES = txt_ADDRES.Text;
                Cus.CONTAT = txt_CONTAT.Text;
                Cus.TELPHO = txt_TELPHO.Text;
                Cus.UEMAIL = txt_UEMAIL.Text;
                Cus.AddID = CookInfo.EAdminid();
                Cus.Adder = CookInfo.EAdminTrueName();
                Cus.AddTime = DateTime.Now;
                Cus.ElseTel = txt_ElseTel.Text;
                Cus.HomeTel = txt_HomeTel.Text;
                Cus.PingYing = PinYinConverter.GetFirst(txt_CUTNAM.Text);
                returnvalue = TbsDbSession.Default.Insert<Proj_Custor>(Cus);
            }
            if (returnvalue > 0)
            {
                Alert.Show("更新成功！", "提示", ActiveWindow.GetHideRefreshReference());
            }
        }

    }
}